#include "Point3.h"
#include <math.h>

Point3::Point3(void)
{
}

Point3::Point3( double x, double y, double z )
{
	this->x = x;
	this->y = y;
	this->z = z;
}

Point3::Point3( Point3* p )
{
	x = p->x;
	y = p->y;
	z = p->z;

}
Point3::~Point3(void)
{
}

double Point3::distanceTo( Point3 p )
{
	double dx = x - p.x;
	double dy = y - p.y;
	double dz = z - p.z;
	return sqrt(dx * dx + dy * dy + dz * dz);
}

double Point3::distanceToSquared( Point3 p )
{
	double dx = x - p.x;
	double dy = y - p.y;
	double dz = z - p.z;
	return dx * dx + dy * dy + dz * dz;
}

Point3* Point3::set( double x, double y, double z )
{
	this->x = x;
	this->y = y;
	this->z = z;
	return this;
}

Point3* Point3::set( Point3 p )
{
	x = p.x;
	y = p.y;
	z = p.z;
	return this;
}

Point3* Point3::add( Point3 p, Vector3 v, Point3* dest )
{
	dest->x = p.x + v.x;
	dest->y = p.y + v.y;
	dest->z = p.z + v.z;
	return dest;
}

Point3* Point3::sub( Point3 p, Vector3 v, Point3* dest )
{
	dest->x = p.x - v.x;
	dest->y = p.y - v.y;
	dest->z = p.z - v.z;
	return dest;
}

Vector3* Point3::sub( Point3 p1, Point3 p2, Vector3* dest )
{
	dest->x = p1.x - p2.x;
	dest->y = p1.y - p2.y;
	dest->z = p1.z - p2.z;
	return dest;
}

Point3* Point3::mid( Point3 p1, Point3 p2, Point3* dest )
{
	dest->x = 0.5 * (p1.x + p2.x);
	dest->y = 0.5 * (p1.y + p2.y);
	dest->z = 0.5 * (p1.z + p2.z);
	return dest;
}